﻿using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Data;
using System.Windows.Documents;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Imaging;
using System.Windows.Navigation;
using System.Windows.Shapes;

namespace ExcelTabToSpace
{
    /// <summary>
    /// MainWindow.xaml 的交互逻辑
    /// </summary>
    public partial class MainWindow : Window
    {
        public MainWindow()
        {
            InitializeComponent();
        }

        private void Button_Click(object sender, RoutedEventArgs e)
        {
            List<List<int>> resultList = new List<List<int>>();
            for (int i = 0; i < srcTextBox.LineCount; i++)
            {
                var result = getData(srcTextBox.GetLineText(i));
                if (result.Count > 0)
                    resultList.Add(result);
            }
            string json = JsonConvert.SerializeObject(resultList);
            destTextBox.Text = json;
        }

        private List<int> getData(string line)
        {
            line = line.Replace("\r\n", "");
            var strList = line.Split(' ').ToList();
            List<int> result = new List<int>();
            for (int i = 0; i < strList.Count; i++)
            {
                if (strList[i].Trim().Length == 0)
                    continue;
                result.Add(int.Parse(strList[i]));
            }
            return result;
        }
    }
}
